package com.bushro.rpc.config.provider;

import com.bushro.rpc.server.RpcServer;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 	$RpcServerConfig 服务器端启动配置类
 * @author bushro
 *
 */
@Slf4j
public class RpcServerConfig {

	private final String host = "127.0.0.1";

	protected int port;

	/**
	 * 服务提供者
	 */
	private List<ProviderConfig> providerConfigs;

	private RpcServer rpcServer = null;

	public RpcServerConfig(List<ProviderConfig> providerConfigs) {
		this.providerConfigs = providerConfigs;
	}

	public void exporter() {
		if(rpcServer == null) {
			try {
				rpcServer = new RpcServer(host + ":" + port);
			} catch (Exception e) {
				log.error("RpcServerConfig exporter exception: ", e);
			}

			for(ProviderConfig providerConfig: providerConfigs) {
				rpcServer.registerProcessor(providerConfig);
			}
		}
		// zk
		//	把所有服务提供的列表注册到zk上
		/**
		 *	/dubbo
		 *		/interface: com.bfxy.service.HelloService
		 *			/providers
		 *				/ip:port (192.168.11.101:8765)
		 *				/ip:port (192.168.11.102:8765)
		 *			/consumers
		 * 				/ip:port
		 * 				/ip:port
		 */
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public List<ProviderConfig> getProviderConfigs() {
		return providerConfigs;
	}

	public void setProviderConfigs(List<ProviderConfig> providerConfigs) {
		this.providerConfigs = providerConfigs;
	}
}
